/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/3/22 20:38
 */
public class MySynchronized {

    static Object object = new Object(); // 锁

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while (true) {
                synchronized (object) {
                   System.out.println("0");
                   object = new Object();
                   try {
                       Thread.sleep(10000);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
           }
        });

        Thread t1 = new Thread(() -> {
            while (true) {
                synchronized (object) {
                    System.out.println("1");
                }
            }
        });
        t.start();
        t1.start();
    }
}
